using Game.Core;
using Game.Main.Model;
using Game.Main.View;
using UnityEngine;

namespace Game.Component
{
	public class ElevatorButtonItem : BaseItem
	{
		public enum State
		{
			Open = 0,
			Close = 1
		}

		private State state;

		private BaseItem elevator;

		private BoxCollider2D[] openColls;

		private BoxCollider2D closeColl;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			BoxCollider2D[] components = model.GetComponents<BoxCollider2D>();
			if (components.Length == 4)
			{
				openColls = new BoxCollider2D[2];
				openColls[0] = components[1];
				openColls[1] = components[2];
				closeColl = components[3];
			}
		}

		public void SetState(State val)
		{
			if (state != val)
			{
				state = val;
				if (state == State.Open)
				{
					openColls[0].enabled = true;
					openColls[1].enabled = true;
					closeColl.enabled = false;
				}
				else
				{
					openColls[0].enabled = false;
					openColls[1].enabled = false;
					closeColl.enabled = true;
				}
			}
		}

		public override void QuicklyTouch(TouchEventData touchEventData)
		{
			base.QuicklyTouch(touchEventData);
			if (elevator == null)
			{
				elevator = Singleton<Scene>.Instance.GetItemByScriptType(73);
			}
			if (elevator != null)
			{
				((ElevatorItem)elevator).OCDoor(true);
			}
		}
	}
}
